<?php
/**

 */
class Admin_ServiceController extends App_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
    	$request=$this->getRequest();  

		$form = new Form_ServiceForm();
		$this->view->form = $form;
    	
		$user_id = $this->getUserId();
		$user_role = 'admin';

		$model_service = new Model_Service();
		
		
		if($request->isPost()){
			$data = $request->getParams();
			if ($data['submit']=='Add Service'){
				$dpt_id=$data['dpt_id'];
				$dpt_name=$data['dpt_name'];
				$description=$data['description'];
				$service_url=$data['service_url'];
				$service_name=$data['service_name'];
				$service_area=$data['service_area'];
				$icon=$data['icon'];
				$transfer_fund_allowed=$data['transfer_fund_allowed'];
				$network_id=$data['network_id'];
				$payment_center_id=$data['payment_center_id'];
								
				$result = $model_service->addService($dpt_id,$dpt_name,$description,$service_url,$service_name, $service_area,$icon,$transfer_fund_allowed,$network_id,$payment_center_id);
    			if ($result>0)
				{
				   $this->view->success_msg="New user has been added Successfully!";
				}else{
				   $this->view->error_msg="Sorry, add user failed.";					
				}				
				
			}else if ($data['submit']=='Update Service'){
				$dpt_id=$data['dpt_id'];
				$dpt_name=$data['dpt_name'];
				$description=$data['description'];
				$service_url=$data['service_url'];
				$service_name=$data['service_name'];
				$service_area=$data['service_area'];
				$icon=$data['icon'];
				$transfer_fund_allowed=$data['transfer_fund_allowed'];
				$network_id=$data['network_id'];
				$payment_center_id=$data['payment_center_id'];
				
				$update = $model_service->updateService($dpt_id,$dpt_name,$description,$service_url,$service_name, $service_area,$icon,$transfer_fund_allowed,$network_id,$payment_center_id);
    			if ($update)
				{
				   $this->view->success_msg="Service data has been added Successfully!";
				}else{
				   $this->view->error_msg="Sorry, update service failed.";					
				}				
			}
			
		}
				
		$all_services = $model_service->getAllService();   					
				
		$this->view->all_services=$all_services;
		    	
    }
        
	public function logoutAction()
	{
		$session = $this->getSession();
		$session->unsetAll();

		$this->_redirect('/');
	}

    
}